package com.example.demo.controller;

import com.example.demo.model.TextDocument;
import com.example.demo.service.TextDocumentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Controller
public class HomeController {

    private final TextDocumentService textDocumentService;

    @Autowired
    public HomeController(TextDocumentService textDocumentService) {
        this.textDocumentService = textDocumentService;
    }

    @GetMapping("/")
    public String home(Model model) {
        List<TextDocument> documents = textDocumentService.getAllDocuments();
        model.addAttribute("documents", documents);
        return "home";
    }
    
    @GetMapping("/documents/{id}")
    public String viewDocument(@PathVariable Long id, Model model) {
        TextDocument document = textDocumentService.getDocumentById(id);
        model.addAttribute("document", document);
        return "document-view";
    }
} 